// pages/recommend/recommend.js
var that,
  api = new (require('../../utils/api.js')),
  headimg = api.getimgurl(),
  app = getApp(),
  util = new (require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    canNum: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that = this
    that.getdata()
  },
  getdata() {
    wx.showLoading({
      title: '加载中...',
    })
    let { page } = that.data
    api.getshareRecord(page, res => {
      wx.hideLoading()
      if (res.data.code == 0) {
        let { canNum, nextPage, recordArr } = res.data.entity.data
        that.setData({ canNum, nextPage, recordArr }, () => {
          if (that.data.canNum > 0) {
            api.usershare(res1 => {
              let { shareKey } = res1.data.entity.data
              that.setData({ shareKey, nextPage })
            })
          }
        })
      }
    })
    let userinfo = wx.getStorageSync('userInfo')
    that.setData({ userinfo })
  },
  tips() {
    wx.showModal({
      title: '提示',
      content: '您的剩余分享次数不足',
      showCancel: !1,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let { nextPage, page } = that.data
    if (nextPage == 1) {
      page = page + 1
      that.setData({ page }, () => {
        that.getdata()
      })
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    let { userinfo, shareKey } = that.data
    if (res.from === 'button') {
      console.log('触发页面内的分享按钮', res.target);

      console.log(res.data, 'eeeee');
      let shareObj = {
        imageUrl: '../pic/shareimg.png',
        title: '您身边的加油好帮手',
        path: 'pages/index/index?shareKey=' + shareKey + '&userinfo=' + JSON.stringify(userinfo)
      }
      console.log(shareObj, 'shareObjshareObj');
      return shareObj
    }
  }
})